#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'base64是一种常见的编码方案'

import base64

# 编码
be1 = base64.b64encode(b'binary\x00string')
print(be1) # b'YmluYXJ5AHN0cmluZw=='

# 解码
bd1 = base64.b64decode(b'YmluYXJ5AHN0cmluZw==')
print(bd1) # b'binary\x00string'

# 处理Base64编码可能出现字符+和/问题
bsf = base64.b64encode(b'i\xb7\x1d\xfb\xef\xff')
print(bsf) # b'abcd++//'

# 将字符+和/分别变成-和_
bsd = base64.urlsafe_b64encode(b'i\xb7\x1d\xfb\xef\xff')
print(bsd) # b'abcd--__'










